//
//  FMDownLoader.h
//  FMDownLoad
//
//  Created by apple on 17/3/20.
//  Copyright © 2017年 apple. All rights reserved.
//

#import <Foundation/Foundation.h>

#define kDownLoadURLOrStateChangeNotification @"downLoadURLOrStateChangeNotification"



typedef NS_ENUM(NSUInteger, FMDownLoaderState) {
    /** 下载暂停 */
    FMDownLoaderStatePause,
    /** 正在下载 */
    FMDownLoaderStateDowning,
    /** 已经下载 */
    FMDownLoaderStateSuccess,
    /** 下载失败 */
    FMDownLoaderStateFailed
};

typedef void(^FMDownLoadedStateChangeBlock)(FMDownLoaderState state);
//typedef void(^DownLoadMessageBlock)(long long totalSize, NSString *downLoadedPath);
typedef void(^DownLoadProgressChangeBlock)(float progress);
//typedef void(^DownLoadSuccessBlock)(NSString * downLoadedPath);
//typedef void(^DownLoadFailedBlock)(NSString * errorMsg);


typedef void(^DownLoadInfoTypeBlock) (long long fileSize);
typedef void(^DownLoadSuccessBlock) (NSString *cacheFilePath);
typedef void(^DownLoadFailTypeBlock)(NSString * errorMsg);



@interface FMDownLoader : NSObject

@property (nonatomic, assign, readonly) FMDownLoaderState state;

@property (nonatomic, copy) FMDownLoadedStateChangeBlock stateChangeBlock;

//@property (nonatomic, copy) DownLoadMessageBlock messageBlock;

@property (nonatomic, copy) DownLoadProgressChangeBlock progressBlock;

//@property (nonatomic, copy) DownLoadSuccessBlock successBlock;

//@property (nonatomic, copy) DownLoadFailedBlock failedBlock;


@property (nonatomic, copy) DownLoadInfoTypeBlock downLoadInfoTypeBlock;

@property (nonatomic, copy) DownLoadSuccessBlock successBlock;

@property (nonatomic, copy) DownLoadFailTypeBlock failedBlock;

@property (nonatomic, assign) float progress;





/**
 *  下载
 *
 *  @param url url
 */
- (void)downLoadedWithUrl:(NSURL *)url;

/**
 *  下载
 *
 *  @param url                   url
 *  @param downLoadInfoTypeBlock 下载信息回调
 *  @param successBlock          成功的回调
 *  @param failBlock             失败的回调
 */
- (void)downLoadedWithUrl:(NSURL *)url downLoadInfoTypeBlock:(DownLoadInfoTypeBlock)downLoadInfoTypeBlock successBlock:(DownLoadSuccessBlock)successBlock failBlock:(DownLoadFailTypeBlock)failBlock;

/**
 *  返回下载完成或者已经缓存完成的路径
 *
 *  @param url 请求的url
 *
 *  @return 请求路径
 */
+ (NSString *)downLoadedFileWithURL: (NSURL *)url;

/**
 *  临时缓存大小
 *
 *  @param url url
 *
 *  @return 临时文件的大小
 */
+ (long long)tmpCacheSizeWithURL: (NSURL *)url;

/**
 *  清除缓存
 *
 *  @param url url
 */
+ (void)clearCacheWithURL: (NSURL *)url;



- (void)pause;

- (void)resume;

- (void)cancel;

- (void)cancelAndClean;

@end
